//
//  SearchViewModel.m
//  DataStatistics
//
//  Created by Kang on 16/6/14.
//  Copyright © 2016年 YTYangK. All rights reserved.
//

#import "SearchViewModel.h"
#import "EquipmenModel.h"           // 设备模型
#import "RemoveBindingModel.h" // 删除模型


//#import "EquipmenDetailsVC.h"

@interface SearchViewModel()

@end

@implementation SearchViewModel
singleton_for_implementation(SearchViewModel)

#pragma mrak - 设备列表
+ (void)requestWithUrlForSearchIn:(id)obj andParam:(NSDictionary *)param
                          success:(void(^)(EquipmenModel *model))success failure:(void(^)(NSString *error))failure {
    
    MDC_INTER_DIC(@"deviceList/deviceList.asp", @"NetMethodPOST", @"false")
    [super initRequestWithUrlObj:obj parametersDic:param Interface:inter success:^(id obj, id model) {
      
        EquipmenModel *equipmen = [[EquipmenModel alloc] initWithDictionary:model error:nil];
        NSLog(@"设备列表数据解析结果：--->%@",equipmen);
        // 这里不做 数组空值判断，因为需要返回到成功，刷新界面
        if (![equipmen.EListModel isEqual:[NSNull null]]) {
            success(equipmen);
        }
    } failure:^(id obj, NSString *err) {
        failure(err); //返回是因为需要列表拉下来
    }];
    
}

     
     
#pragma mark - 删除绑定
+ (void)requestWithUrlForDeviceRemoveBinding:(id)obj andParam:(NSDictionary *)param success:(void(^)(RemoveBindingModel *model))success failure:(void(^)(NSString * error))failure {
    
    MDC_INTER_DIC(@"deviceList/deviceRemoveBinding.asp", @"NetMethodPOST", @"false")
    [super initRequestWithUrlObj:obj parametersDic:param Interface:inter success:^(id obj, id model) {
        RemoveBindingModel *removeBinding = [[RemoveBindingModel alloc] initWithDictionary:model error:nil];
        
        RemoveBindingList * list = removeBinding.RemoveBindingList[0];
        int returnCode = list.result;
        if (returnCode == 0) {
            failure(NSLocalizedString(@"SysLead_Delete", nil));
        }
        else if (returnCode == 1) {
            success(removeBinding);
        }
        else {
            // 未绑定
            failure(NSLocalizedString(@"SysLead_Been", nil));
        }
    } failure:^(id obj, NSString *err) {
        [MBProgressHUD showError:err]; //返回是因为需要列表拉下来
    }];
}


#pragma mark - 跳转日志列表
+ (void)jumpListDetailWithListModel:(EListModel *)model forViewController:(id)vc {
    [vc performSegueWithIdentifier:@"jumpJournalList" sender:vc];
    
    //获取当前设备名
    [NSUD setObject:model.device_id forKey:@"device_name"];
    
}


@end
